package cn.com.ali.maxcompute;
import java.util.List;

import com.aliyun.odps.Column;
import com.aliyun.odps.Instance;
import com.aliyun.odps.Odps;
import com.aliyun.odps.OdpsException;
import com.aliyun.odps.account.Account;
import com.aliyun.odps.account.AliyunAccount;
import com.aliyun.odps.data.Record;
import com.aliyun.odps.task.SQLTask;
public class SDKTests {
    private static final String sql = "select * from zdjx.t_shujufuwu;";
    public static void main(String[] args) {
        Account account = new AliyunAccount(Config.ACCESSID, Config.ACCESSKEY);
        Odps odps = new Odps(account);
        odps.setEndpoint(Config.ENDPOINT);
        odps.setDefaultProject(Config.PROJECT);
        Instance i;
        try {
            i = SQLTask.run(odps, sql);
            i.waitForSuccess();
            List<Record> records = SQLTask.getResult(i);
            for(Record r:records){
                Column[] columns = r.getColumns();
                for(int j=0;j<columns.length;j++) {
                    System.out.println(columns[j].getName() + ":\t\t" +r.get(j) + "\t");
                }
            }
        } catch (OdpsException e) {
            e.printStackTrace();
        }
    }
}
